import Services from './services';
import Vue from 'vue';

let schedule = require('node-schedule');

class BaseJob {

    constructor() {
        this.instence = undefined;
    }

    get $f7() {
        return Vue.prototype.$f7;
    }

    get $framework() {
        return Services.getInstance("framework");
    }

    get anonymous() {
        return false;
    }

    get cron() {
        return undefined;
    }

    register(cron = this.cron) {
        if (cron != undefined) {
            if (this.instence != undefined) {
                this.instence.cancel();
            }
            this.instence = schedule.scheduleJob(cron, () => {
                // console.log("job");
                this.doJob();
            });
        }
    }

    cancel() {
        if (this.instence != undefined) {
            this.instence.cancel();
            this.instence = undefined;
        }
    }

    doJob() {

    }

}

export default BaseJob;